/* eslint-disable */
<template>
  <div class="list-model">
    <div class="table-box">
      <el-table
        :data="list"
        size="mini"
        style="width: 100%"
        class="hightline-box"
      >
        <el-table-column
          prop="productNo"
          label="资源编号"
          min-width="120"
        >
          <template slot-scope="scope">
            <span v-html="hightline(scope.row.productNo)"></span>
          </template>
        </el-table-column>
        <el-table-column
          prop="productName"
          label="资源名称"
          min-width="100"
        >
          <template slot-scope="scope">
            <span v-html="hightline(scope.row.productName)"></span>
          </template>
        </el-table-column>
        <el-table-column
          label="规格"
          min-width="140"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.productType===2">
              语音识别
            </div>
            <div v-else>
              <div v-html="hightline(`vCPU: ${scope.row.vCpu}核`)"> </div>
              <div>内存: {{`${toGB(scope.row.memory)}GB`}}</div>
              <div>存储: {{`${toGB(scope.row.dataTotal)}GB`}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="productType"
          label="资源类型"
          min-width="100"
        >
          <template slot-scope="scope">
            <div>{{scope.row.productType===1?'虚拟资源':scope.row.productType===2?'模型':'物理资源'}}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="productSource"
          label="来源"
          min-width="100"
        >
          <template slot-scope="scope">
            <div>{{scope.row.productSource===1?'个人':scope.row.productType===2?'企业':'平台'}}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="单价(元/分钟)"
          min-width="100"
        >
          <template slot-scope="scope">
            <div
              v-if="scope.row.price===null"
              class="tobeConfigured"
            >{{isADMIN?'待配置':'待更新'}}</div>
            <div v-else>{{scope.row.price}}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="billType"
          label="计费类型"
          min-width="100"
        >
          <template slot-scope="scope">
            <div
              v-if="scope.row.billType===null"
              class="tobeConfigured"
            >{{isADMIN?'待配置':'待更新'}}</div>
            <div v-else>{{scope.row.billType===0?' 按量计费':'-'}}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="billRule"
          label="计费规则"
          min-width="100"
        >
          <template slot-scope="scope">
            <div
              v-if="scope.row.billRule===null"
              class="tobeConfigured"
            >{{isADMIN?'待配置':'待更新'}}</div>
            <div v-else>{{scope.row.billRule===1?'梯度计费':'标准计费'}}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="时间"
          min-width="180"
        >
          <template slot-scope="scope">
            <div>部署: {{scope.row.deployTime}}</div>
            <div>更新: {{scope.row.updateTime}}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="totalIncome"
          label="累计收入(元)"
          min-width="100"
        >
          <template slot-scope="scope">
            <div
              v-if="scope.row.totalIncome===null"
              class="tobeConfigured"
            >{{isADMIN?'待配置':'待更新'}}</div>
            <div v-else>{{scope.row.totalIncome}}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          width="60"
          v-if="isADMIN"
        >
          <template slot-scope="scope">
            <el-tooltip
              content="计费配置"
              placement="top"
              v-auth="['operation:product:config']"
            >
              <img
                src="../../_source/image/billing/billingSetting.svg"
                @click="_edit(scope.row)"
              >
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <clacSetting
      ref="clacSetting"
      @update="update"
    />
  </div>
</template>
<script>
  import clacSetting from './clacSetting.vue'
  import store from '@/conf/home/store'
  export default {
    name: 'tenement-list',
    data () {
      return {
        list: [],
        isADMIN: store.state.user.userInfo.userType === 'ADMIN_USER',
      }
    },
    props: {
      searchVal: String,
      tenementList: Array,
      pageNo: Number,
      pageSize: Number
    },
    methods: {
      _edit (row) {
        this.$refs.clacSetting.show(row)
      },
      toGB (count) {
        return (count / 1024 / 1024 / 1024).toFixed(1) || 0
      },
      update () {
        this.$emit('on-update')
      },
      hightline (val) {
        if (val) {
          if (!this.searchVal) return val
          /* 转字符 */
          let newval = val + ''
          const rep = new RegExp(this.searchVal, 'gi')
          const str = `<span class='active'>${this.searchVal}</span>`
          return newval.replace(rep, str)
        } else {
          return '--'
        }
      },
    },
    watch: {
      tenementList (a) {
        this.list = []
        setTimeout(() => {
          this.list = a
        })
      }
    },
    created () {
      this.list = this.tenementList
    },
    mounted () { },
    components: { clacSetting }
  }
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
/deep/.hightline-box {
  .active {
    color: red !important;
  }
}
.tobeConfigured {
  width: 62px;
  height: 20px;
  background: rgba(242, 112, 17, 0.2);
  border: 1px solid rgba(242, 112, 17, 0.4);
  border-radius: 11px;
  font-size: 12px;
  font-family: PingFang SC, PingFang SC-400;
  font-weight: 400;
  text-align: center;
  color: #f27011 !important;
  line-height: 20px;
}
.cli {
  // margin-left: 12px;
  font-size: 14px;
  font-family: PingFang SC, PingFang SC-Regular;
  font-weight: 400;
  text-align: LEFT;
  color: #33317e;
  line-height: 20px;
  cursor: pointer;
}
.otherCli {
  width: 10px;
  margin-left: 12px;
  font-size: 14px;
  font-family: PingFang SC, PingFang SC-Regular;
  font-weight: 400;
  text-align: LEFT;
  color: #33317e;
  // background: #fff;
  line-height: 20px;
  border: 0;
  cursor: pointer;
}
</style>
